package com.xiaoran.springboot4.demo.controller;

import com.xiaoran.springboot4.demo.bean.City;
import com.xiaoran.springboot4.demo.bean.User;

import com.xiaoran.springboot4.demo.service.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
//@RestController
@Slf4j
public class TestController {
    @Autowired
    ServiceImpl service;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/user")
    @ResponseBody
    public User getUser1( ){
        log.info("*********************************************");
        User user=service.getid(1);
        return user;
    }

    @ResponseBody
    @GetMapping("/sql")
    public int querForList(){
        int i=jdbcTemplate.queryForObject("select count(*) from t1",Integer.class);
        return i;
    }

    @ResponseBody
    @GetMapping("/city")
    public City city1(@RequestParam("id") int id){
      City city=  service.city(id);
        return  city;
    }

    @PostMapping("/cc")
    @ResponseBody
    public City saveCity(City city){
          service.insettto(city);
        return city;
    }

}
